<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php


class UserIdentity extends CUserIdentity
{
	public function authenticate()
	{
		$uerObject = new CUserValid();
		$user = $uerObject->validUser($this->username,$this->password);
		if(!isset($user) || !$user){
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
			return false;
		}
		$userBase = new UserBase();
		$userBase->load($user->id);
		Yii::app()->session["user"]=$userBase->serialize();
				Yii::app()->session["appId"] = 1;		$userDevice = new UserDevice();
		$device = $userDevice->find("user_id=? and user_device_type=1",$userBase->id);		if(!isset($device)){
			$device = new UserDevice();
			$device->user_device_uuid=CUtils::genRandomString(32);
			$device->user_id = $userBase->id;
			$device->user_device_type=1;
			$device->user_device_name="web";
			$device->user_device_info="web";
			$device->save();
		}
		Yii::app()->session["deviceId"] = $device->id;		$this->errorCode=self::ERROR_NONE;
		return true;
	}
}